//
// Created by lanlu on 2025/8/5.
//

#include <queue>
#include <iostream>
using namespace std;

struct Student {
    string name;
    int score;

    Student(string name, int score) : name(name), score(score)
    {
    }
};

struct CompareStudent {
    // 运算符重载 目的是比较两个student对象
    // 可以让结构体像函数一样被调用  “函数对象”
    bool operator()(Student a, Student b)
    {
        // 如果返回true 则 b优先级高
        // 如果返回false 则 a优先级高
        if (a.score != b.score)
        {
            // 分数高的优先级高
            return a.score < b.score;
        }
        // 按照名字字母的优先级排序  字母在前的优先级高
        return a.name > b.name;
    }
};

int main()
{
    priority_queue<int> pq;
    pq.push(10);
    pq.push(20);
    pq.push(5);
    pq.push(15);

    while (!pq.empty())
    {
        cout << pq.top() << " ";
        pq.pop();
    }
    cout << endl;

    // greater<int> 意思是 队首是最小值
    priority_queue<int, vector<int>, greater<int> > minqueue;
    minqueue.push(10);
    minqueue.push(20);
    minqueue.push(5);
    minqueue.push(15);

    while (!minqueue.empty())
    {
        cout << minqueue.top() << " ";
        minqueue.pop();
    }
    cout << endl;

    // 自定义排序规则
    priority_queue<Student, vector<Student>, CompareStudent> student_pq;
    student_pq.push(Student("zhangsan", 90));
    student_pq.push(Student("lisi", 80));
    student_pq.push(Student("wangwu", 85));
    student_pq.push(Student("zhaoliu", 85));
    while (!student_pq.empty())
    {
        Student s = student_pq.top();
        cout << s.name << " " << s.score << endl;
        student_pq.pop();
    }

    CompareStudent cmp;
    cout << cmp(Student("zhangsan", 70), Student("lisi", 80)) << endl;

    return 0;
}
